Better version of the previous patch
authorMatthias Clasen <matthiasc@src.gnome.org>
Sun, 29 Apr 2007 18:22:27 +0000 (18:22 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sun, 29 Apr 2007 18:22:27 +0000 (18:22 +0000)
svn path=/trunk/; revision=17712

ChangeLog
gtk/gtkprintoperation-unix.c

index a1af309b0f59ea970faeaff83eb9471e21f1cee9..5cfa55373522a2e566b15d5d48f3328728686f7f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,7 +10,7 @@
        * gtk/gtkprintoperation-unix.c 
        (_gtk_print_operation_platform_backend_launch_preview):
        Don't leak a file descriptor, and don't make the error
-       dialog modal.  (#421985, Morten Welinder)
+       dialog modal.  (#421985, Morten Welinder, Christian Persch)
 
 2007-04-29  Xan Lopez  <xan@gnome.org>
 
index d254c5ffed3feb675def8af281f9594117131ffe..e76313ac74498e4779efa9f959e176a75d889e64 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdlib.h>       
 #include <fcntl.h>
 
+#include <glib/gstdio.h>
 #include "gtkprintoperation-private.h"
 #include "gtkmarshal.h"
 #include "gtkmessagedialog.h"
@@ -124,14 +125,12 @@ shell_command_substitute_file (const gchar *cmd,
                                gboolean    *settings_filename_replaced)
 {
   const gchar *inptr, *start;
-  gchar *result;
   GString *final;
 
   g_return_val_if_fail (cmd != NULL, NULL);
   g_return_val_if_fail (pdf_filename != NULL, NULL);
   g_return_val_if_fail (settings_filename != NULL, NULL);
 
-  result = NULL;
   final = g_string_new (NULL);
 
   *pdf_filename_replaced = FALSE;
@@ -170,11 +169,7 @@ shell_command_substitute_file (const gchar *cmd,
     }
   g_string_append (final, start);
 
-  result = final->str;
-
-  g_string_free (final, FALSE);
-
-  return result;
+  return g_string_free (final, FALSE);
 }
 
 void
@@ -189,14 +184,15 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
   gchar *preview_cmd;
   GtkSettings *settings;
   GtkPrintSettings *print_settings;
-  gchar *settings_filename;
+  gchar *settings_filename = NULL;
   gchar *quoted_filename;
   gchar *quoted_settings_filename;
-  gboolean filename_used;
-  gboolean settings_used;
+  gboolean filename_used = FALSE;
+  gboolean settings_used = FALSE;
   GdkScreen *screen;
   GError *error = NULL;
   gint fd;
+  gboolean retval;
 
   cairo_surface_destroy (surface);
  
@@ -205,11 +201,15 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
   else
     screen = gdk_screen_get_default ();
 
-  settings_filename = g_build_filename (g_get_tmp_dir (), "settingsXXXXXX.ini", NULL);
-  fd = g_mkstemp (settings_filename);
+  fd = g_file_open_tmp ("settingsXXXXXX.ini", &settings_filename, &error);
+  if (fd < 0) 
+    goto out;
 
   print_settings = gtk_print_operation_get_print_settings (op);
-  if (!gtk_print_settings_to_file (print_settings, settings_filename, &error))
+  retval = gtk_print_settings_to_file (print_settings, settings_filename, &error);
+  close (fd);
+
+  if (!retval)
     goto out;
 
   settings = gtk_settings_get_for_screen (screen);
@@ -233,8 +233,6 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
   g_strfreev (argv);
 
  out:
-  close (fd);
-
   if (error != NULL)
     {
       GtkWidget *edialog;